<template>
	<view class="pad-lr-24 pad-tb-20">
		<view class="radius-20 bgfff pad-tblr-30">
			<view class="display align-items tx_view" v-if="isLogin">
				<image :src="info?.user.avatar" class="proudct-item-icon-6 border-50" mode=""></image>
				<view class="ml20">
					<view class="fontSize-36 fontBold">{{info?.user.nickname}}</view>
					<view class="fontSize-28 col-6 mar-top-16">{{info?.user.mobile}}</view>
				</view>
			</view>
			<button class="tel_btn display-ce align-items fontSize-32 col-f fontBold" open-type="getPhoneNumber" @getphonenumber="getphonenumber" v-else>获取手机号</button>
			<view class="display-ce align-items mar-top-28">
				<view class="width32 text-align-center" @click="goamount">
					<view class="fontSize-32 fontBold">{{info?.user.money||0}}</view>
					<view class="col-6 mar-top-26 fontSize-26">可提金额(元)</view>
				</view>
				<view class="width32 text-align-center borderleft col-FD6317">
					<view class="fontSize-32 fontBold">{{info?.max_price||0}}</view>
					<view class=" mar-top-26 fontSize-26">待返金额(元)</view>
				</view>
				<view class="width32 text-align-center borderleft" @click="gorecords">
					<view class="fontSize-32 fontBold">{{info?.withdraw_money||0}}</view>
					<view class="col-6 mar-top-26 fontSize-26">已提金额(元)</view>
				</view>
			</view>
		</view>
		<view class="mar-top-20 bgfff pad-lr-30 pad-tb-40 radius-20">
			<view class="fontBold fontSize-34">我的服务</view>
			<view class="display align-items flex-wrap">
				<button class="width25 text-align-center mar-top-34 mb16" v-for="item in list" :key="item.id" @click="gopath(item.path)" :open-type="item.id==4?'contact':''">
					<image :src="item.image" class="proudct-item-icon-30" mode=""></image>
					<view class="fontSize-26 col-6 mar-top-40">{{item.name}}</view>
				</button>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
import { onShow } from '@dcloudio/uni-app';
import { ref } from 'vue';
import {wxAuthorization,centerindex} from "../../utils/api"
const isLogin = ref(false)
const info = ref()
onShow(()=>{
	_centerindex()
	if(uni.getStorageSync('token')){
		isLogin.value = true
	}else{
		isLogin.value = false
	}
})
const list = ref([
	{image:'/static/img/icon3.png',id:1,name:'机具绑定',path:'/mypages/bind/bind'},
	{image:'/static/img/icon4.png',id:2,name:'我的订单',path:'/mypages/myorder/myorder'},
	{image:'/static/img/icon5.png',id:3,name:'我的收益',path:'/mypages/myearnings/myearnings'},
	{image:'/static/img/icon6.png',id:4,name:'专属客服',path:''},
	{image:'/static/img/icon7.png',id:5,name:'返还邮费',path:'/mypages/mymachine/mymachine'}
])
const getphonenumber =(e) =>{
	uni.login({
		success(res) {
			wxAuthorization({
				code:res.code,
				mobile_code:e.detail.code
			}).then(res=>{
				if(res.code==1){
					uni.setStorageSync('token',res.data.token)
					_centerindex()
				}
			})
		}
	})
}
const _centerindex =() =>{
	centerindex().then(res=>{
		if(res.code==1){
			info.value = res.data
			isLogin.value = true
		}else if(res.code==303){
			isLogin.value = false
		}
	})
}
const goamount =() =>{
	uni.navigateTo({
		url:'/mypages/amount/amount'
	})
}
const gorecords =() =>{
	uni.navigateTo({
		url:'/mypages/records/records'
	})
}
const gopath =(path:string) =>{
	uni.navigateTo({
		url:path
	})
}
</script>

<style lang="scss">
@import 'my.scss';
</style>
